package com.ssfeng.youxia.shiro;

import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authc.LogoutFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * Created by liyuhang on 2019-09-06.
 */
public class SystemLogoutFilter extends LogoutFilter {

    private static final Logger logger = LoggerFactory.getLogger(SystemLogoutFilter.class);

    @Override
    protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
        Subject subject = getSubject(request, response);
        String redirectUrl = getRedirectUrl(request, response, subject);
        try {
            logger.debug("开始退出登录");
            subject.logout();
        } catch (Exception ise) {
            ise.printStackTrace();
        }
        issueRedirect(request, response, redirectUrl);
        return false;
    }

    public SystemLogoutFilter() {
        super.setRedirectUrl("/tpage/index.html");
    }
}
